package com.hong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hong.dto.QueryPageEmployeeDTO;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hong.domain.Employee;
import com.hong.dao.EmployeeMapper;
import com.hong.service.EmployeeService;
import org.springframework.util.StringUtils;

@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService{

    @Override
    public Employee getById(Integer id) {
        return baseMapper.selectById(id);
    }

    @Override
    public int updateBatch(List<Employee> list) {
        return baseMapper.updateBatch(list);
    }

    @Override
    public int updateBatchByIds(List<Employee> list) {
        return baseMapper.updateBatchByIds(list);
    }

    @Override
    public boolean insertOrUpdate(Employee record) {
//        return baseMapper.insertOrUpdate(record);
        return true;
    }
    @Override
    public int insertOrUpdateSelective(Employee record) {
        return baseMapper.insertOrUpdateSelective(record);
    }

    @Override
    public Integer updateNameById(Employee employee) {

        return baseMapper.updateNameById(employee.getName(),employee.getId());
    }

    @Override
    public IPage<Employee> getPage(QueryPageEmployeeDTO param) {

        LambdaQueryWrapper<Employee> queryWrapper =new LambdaQueryWrapper<Employee>().eq(StringUtils.hasLength(param.getName()), Employee::getName, param.getName());


        LambdaQueryWrapper<Employee> wrapper = Wrappers.<Employee>lambdaQuery().eq(StringUtils.hasLength(param.getName()), Employee::getName, param.getName());


        Wrappers.<Employee>lambdaUpdate().eq(StringUtils.hasLength(param.getName()), Employee::getName, param.getName());

        IPage<Employee> employeePage = baseMapper.selectPage(new Page<>(param.getPageNum(), param.getPageSize()), queryWrapper);


        IPage<Employee> employeeIPage = baseMapper.selectByNamePage(new Page<>(param.getPageNum(), param.getPageSize()), null);


        return employeePage;
    }
}
